package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "店铺营业状态设置")
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    private final static String SHOP_STATUS = "SHOP_STATUS";

    @PutMapping("/admin/shop/{status}")
    @ApiOperation("设置店铺状态")
    public Result setStatus(@PathVariable("status") Integer status){
        redisTemplate.opsForValue().set(SHOP_STATUS,status);
        return Result.success();
    }

    @GetMapping("/admin/shop/status")
    @ApiOperation("查询店铺营业状态")
    public Result getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
        return Result.success(status);
    }

    @GetMapping("/user/shop/status")
    @ApiOperation("查询用户端营业状态")
    public Result getUserStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
        return Result.success(status);
    }
}
